package com.suntianci.stock.job;

import com.suntianci.stock.service.StockTimerTaskService;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @ClassName StockJobHandler
 * @Author 孙天赐
 * @Date 2025/1/6 10:15
 * @Description TODO: 定义xxlJob任务执行器bean
 */
// @Component：被spring管理
@Component
public class StockJobHandler {

    @Autowired
    private StockTimerTaskService stockTimerTaskService;

    /**
     * 1、简单任务示例（Bean模式）
     */
    @XxlJob("myJobHandler")
    public void demoJobHandler() throws Exception {
        System.out.println("当前时间点为：" + DateTime.now().toString("yyyy-MM-dd HH:mm:ss"));
    }

    /**
     * 定义定时任务，采集国内大盘数据
     */
    @XxlJob("getStockInnerMarketInfos")
    public void getStockInnerMarketInfos(){
        stockTimerTaskService.getInnerMarketInfo();
        System.out.println("\n" + DateTime.now().toString("yyyy-MM-dd HH:mm:ss") + " A股大盘数据采集完成！");
    }

    /**
     * 定时采集A股个股数据
     */
    @XxlJob("getStockRtIndexInfo")
    public void getStockInfos(){
        stockTimerTaskService.getStockRtIndexInfo();
        System.out.println("\n" + DateTime.now().toString("yyyy-MM-dd HH:mm:ss") + " A股个股数据采集完成！");
    }

    /**
     * 定时采集A股板块数据
     */
    @XxlJob("getStockBlockRtIndexInfo")
    public void getStockBlockRtIndexInfo(){
        stockTimerTaskService.getStockBlockRtIndexInfo();
        System.out.println("\n" + DateTime.now().toString("yyyy-MM-dd HH:mm:ss") + " A股板块数据采集完成！");
    }

    /**
     * 定时采集国外大盘数据
     */
    @XxlJob("getStockOuterMarketInfos")
    public void getStockOuterMarketInfos(){
        stockTimerTaskService.getOuterMarketInfo();
        System.out.println("\n" + DateTime.now().toString("yyyy-MM-dd HH:mm:ss") + " 外盘数据采集完成！");
    }
}
